<template>
	<div>
		<div style="width:100%;text-align: center;margin-top: 10px;">
			<div>
				<label>表:&nbsp;</label>
				<el-select placeholder="请选择" filterable v-model="tableName" clearable size="mini">
					<el-option v-for="item in tableList" :key="item.value" :label="item.name" :value="item.value">
					</el-option>
				</el-select>
			</div>
			<div>
				<el-upload drag :action="url" :show-file-list="true" :before-upload="beforeUpload" :headers="headers"
					:on-success="onSuccess" style="margin-top: 10px;">
					<i class="el-icon-upload">
					</i>
					<div class="el-upload__text">
						拖放文件 <em>单击上传</em>
					</div>
				</el-upload>
			</div>
		</div>
	</div>
</template>

<script>
	import constants from '@/utils/constants.js';
	import restUtil from '@/utils/restUtil.js';
	export default {
		name: "ImportFilePage",
		props: ["currentId", "model"],
		data() {
			return {
				headers: {
					"X-Token": window.localStorage.getItem("token")
				},
				url: "",
				
				tableName:"",
				tableList:[]
			}
		},mounted() {
			this.init();
		},
		methods: {
			init(){
				var that = this;
				restUtil.getAction(this,"fileimport/init").then(
					function(response) {
						if (response.data.code == 1) {
							that.tableList = response.data.tableList;
						} else {
							that.$alert(response.data.message, '提示')
						}
				});
			},
			beforeUpload() {
				return new Promise((resolve) => {
					this.url = constants.ROOT_URL + "fileimport/upload?model=" + this.tableName;
					resolve();
				})
			},
			onSuccess() {
				this.$alert("导入成功", '提示');
			}
		}
	}
</script>

<style>
</style>
